// Sorting.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "QuickSort.h"
#include "InsertionSort.h"
#include "HeapSort.h"

#include <gtest/gtest.h>

using namespace CodeMood;

TEST(SortingTest, quick_sort)
{
	vector<int> vec(M);
	//vec.reserve(M);
	generate_random(begin(vec), end(vec));	
	TIME(test_sorting(quick_sort, vec));
	EXPECT_TRUE(is_sorted(begin(vec), end(vec)));
}

TEST(SortingTest, std_sort)
{
	vector<int> vec(M);
	//vec.reserve(M);
	generate_random(begin(vec), end(vec));	
	TIME(std::sort(begin(vec), end(vec)));
	EXPECT_TRUE(is_sorted(begin(vec), end(vec)));
}

TEST(SortingTest, insertion_sort)
{
	vector<int> vec(M);
	//vec.reserve(M);
	generate_random(begin(vec), end(vec));	
	TIME(test_sorting(insertion_sort, vec));
	EXPECT_TRUE(is_sorted(begin(vec), end(vec)));
}

TEST(SortingTest, heap_sort)
{
	vector<int> vec(M);
	//vec.reserve(M);
	//generate_random(begin(vec), end(vec));	
	iota(begin(vec), end(vec), 0);
	srand(0);
	random_shuffle(begin(vec)+1, end(vec));

	TIME(test_sorting(heap_sort, vec));
	EXPECT_TRUE(is_sorted(begin(vec), end(vec)));
}

int _tmain(int argc, _TCHAR* argv[])
{
	//vector<int> vi(300000000);
	//array<int, M> arr;		// array don't have a move constructor,
	//generate_random(arr);	// we have to write this ugly code.
							// std::array allocates memory in stack, not in heap,
							// so we cannot define a too large std::array in stack
	//TIME(test_sorting(quick_sort, arr));
	//print(arr);
	
	//TIME(std::sort(begin(arr), end(arr)));
	//assert(sorted(arr));
	//print(arr);

	//shuffle(arr);
	//TIME(test_sorting(insertion_sort, arr));
	//print(arr);

	//shuffle(begin(arr)+1, end(arr));
	//print(arr);
	//TIME(test_sorting(heap_sort, arr));
	//print(arr);

	::testing::InitGoogleTest(&argc, argv);
	RUN_ALL_TESTS();

	return 0;
}

